home *** CD-ROM | disk | FTP | other *** search
- #!/usr/bin/perl -w
-
- use Debian::DictionariesCommon q(:all);
- use Getopt::Long;
- Getopt::Long::Configure(pass_through,no_auto_abbrev);
-
- # Autoflush output buffers
- $|=1;
-
- # Function to convert ISO-8859-1 (latin1) accented characters to
- # non-accented one. Of course, this only works for west European
- # languages. We might try to find a more general solution based on
- # the current locale character set.
-
- sub isoconv {
- my $s = shift;
- $s =~ y{A-Z┴╔═╙┌▌ßΘφ≤·²└╚╠╥┘αΦ∞≥∙┬╩╬╘█ΓΩε⌠√─╦╧╓▄Σδ∩÷▀ⁿ ├╟╨╤╒πτ±⌡┼╞╪σµ°}
- {a-zaeiouyaeiouyaeiouaeiouaeiouaeiouaeiouaeiosuyacdnoacnoaeoaeo};
- return $s;
- }
-
- #
- # Function to try getting $lang after emacsen name
- #
-
- sub try_emacsen () {
- return unless ( $emacsen );
- my @available_emacsen = ();
- foreach $k (keys %$dictionaries) {
- my $language = $dictionaries->{$k};
- my $hashname = $language->{"hash-name"};
- my $emacsenname = exists $language->{"emacsen-name"} ?
- $language->{"emacsen-name"} : $hashname;
- return $k if ( lc($emacsen) eq lc($emacsenname) );
- push @available_emacsen,$emacsenname;
- }
- print STDERR "Available emacs dict names are:\n";
- foreach ( sort @available_emacsen ){
- print STDERR " $_\n";
- }
- die "$0: Selected emacs dict name [$emacsen]
- does not match any of the available values\n";
- }
-
- #
- # Function to try getting $lang after $regexp
- #
-
- sub try_regexp () {
- return unless $regexp;
- my @regexp_matches = ();
- $regexp = isoconv ($regexp);
- foreach $key ( keys %$dictionaries ) {
- $_ = isoconv ( $key );
- push (@regexp_matches, $key)
- if /$regexp/;
- }
- if (scalar @regexp_matches == 1){
- return $regexp_matches[0];
- } elsif ( scalar @regexp_matches == 0 ) {
- die "$0: No installed language matched `$regexp'\n";
- } else {
- die ("$0: More than one installed languages matched `$regexp':\n "
- . join ("\n ", @regexp_matches) . "\n");
- }
- }
-
- # --------------------------------------------------------------------
- # Now the main program
- # --------------------------------------------------------------------
-
- my $lang = '';
- my $class = "ispell";
- my $cli_opts = "";
-
- $dictionaries = loaddb ("ispell");
-
- # In the POD section below there is an extensive description on the
- # priority order for determining the ispell language.
-
- $emacsen = '';
- $regexp = '';
- my $dryrun = '';
-
- GetOptions ('emacs=s' => \$emacsen,
- 'language=s' => \$regexp,
- 'dry-run' => \$dryrun);
-
- die " ispell-wrapper is a wrapper to ispell, but ispell is not installed.\n"
- unless ( -x "/usr/bin/ispell" );
-
- $regexp = $ENV{ISPELLDEFAULT} unless $regexp;
-
- $regexp =~ s/([^\\]|^)(\(|\))/$1\\$2/g if $regexp; # Make sure () are escaped
-
- $lang = &try_emacsen ()
- || &try_regexp ()
- || &getuserdefault ()
- || &getsysdefault ();
-
- print STDERR " Warning: --language=$regexp will be overriden by
- --emacs=$emacsen setting\n\n"
- if ( defined $lang && $regexp && $emacsen );
-
- $ispell_wrapper_args = &dc_get_spellchecker_params($class,$dictionaries->{$lang});
-
- # Ignore $lang results if -d is set from commandline
-
- foreach ( @ARGV ) {
- if (/^\-d/){
- $ispell_wrapper_args = "";
- }
- $cli_opts .= " $_";
- }
-
- print STDERR "Warning: \'$lang\' values overriden with \'$cli_opts\'\n"
- if ( not $ispell_wrapper_args && defined $lang );
-
- $command_to_run = "ispell $ispell_wrapper_args $cli_opts";
-
- if ( $dryrun ){
- print "--\n$command_to_run\n--\n";
- } else {
- exec $command_to_run;
- }
-
- # Local Variables:
- # perl-indent-level: 2
- # End:
-
- __END__
-
- =head1 NAME
-
- B<ispell-wrapper> - smart wrapper for ispell
-
- =head1 SYNOPSIS
-
- ispell-wrapper [--emacs=name] [--language=regexp] [--dry-run] [ispell options] file
-
- Options (all long only options):
- --emacs=name Set the language to use by emacs dict name
- --language=regexp Set the language to use by name
- --dry-run Only show what would have done
-
- =head1 DESCRIPTION
-
- B<ispell-wrapper> is a wrapper script for ispell intended to be used
- in a Debian system in conjunction with the infrastructure introduced by
- the dictionaries-common package. Option --dry-run will show the string
- to be run without doing anything else.
-
- It automatically sets the B<-d>, B<-w>, and B<-T> options to ispell as a
- function of the chosen language. Of course, this only works for dictionary
- packages that comply with the above mentioned Policy.
-
- Here is how the language is defined (in order of priority):
-
- =over
-
- =item 1)
-
- By matching the emacs dict name given in --emacs option to the name of
- one of the emacs dicts names provided by installed languages in the
- system. This match must be exact (although is case insensitive).
- Note that this will override any value given in the --language option.
-
- =item 2)
-
- By matching the regexp given in option --language to the list of
- installed languages in the system.
-
- =item 3)
-
- By matching the regexp stored in the environment variable
- ISPELLDEFAULT to the list of installed languages in the system.
-
- =item 4)
-
- By using the value stored in the user-specific file ~/.ispell-default
- (use select-default-iwrap(1) to set it).
-
- =item 5)
-
- By using the value stored in the site-wide file
- /etc/dictionaries-common/ispell-default (use select-default-ispell(8)
- as superuser to set it).
-
- =back
-
- Note: regexp matches are case-insensitive and the ISO-8859-1 special
- characters are transformed into their ASCII equivalents. German
- ess-zet is equivalent to the character "s" and the ae ligature to the
- character "e".
-
- =head1 EXAMPLE
-
- Let us say that the following dictionaries are installed in the system
- (as appearing in the Debconf question at installation time):
-
- castellano (Spanish TeX mode)
- castellano8 (Spanish 8 bit)
- portuguΩs (European Portuguese)
- portuguΩs brasileiro (Brazilian Portuguese)
-
- Choosing the regexp (either in the --language option or in the
- environment variable ISPELLDEFAULT) to be "span" will yield an error,
- since two languages will match ("castellano" and "castellano8").
- However, if the regexp is "span.*8", the language "castellano8
- (Spanish 8 bit)" will be chosen.
-
- =head1 ENVIRONMENT
-
- =over
-
- =item ISPELLDEFAULT
-
- Regexp that matches the name of the default language to use, if no
- --language option is given.
-
- =back
-
-
- =head1 FILES
-
- =over
-
- =item $HOME/.ispell-default
-
- Contains the name of the language to use, if no --language option is
- given or if the ISPELLDEFAULT environment variable is not set. This
- is a user-specific choice.
-
- =item /etc/dictionaries-common/ispell-default
-
- Name of the language to use when everything above is not set. This is
- a system-wide setting.
-
- =back
-
-
- =head1 SEE ALSO
-
- select-default-ispell(8), select-default-iwrap(1)
-
- =head1 AUTHORS
-
- Rafael Laboissiere
-
- =cut
-